// 云函数入口文件
const cloud = require('wx-server-sdk');

cloud.init();
const db = cloud.database();

// 数据库集合名称
const COLLECTION_NAME = 'user_info';

exports.main = async (event, context) => {
  const { userInfo } = event;
  try {
    return await db.collection(COLLECTION_NAME).add({
      data: userInfo,
    });
  } catch (e) {
    console.error(e);
    return {
      success: false,
      error: e.message,
    };
  }
};